import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:provide/provide.dart';
import 'package:study_flutter/yzhg/project/service/service_method.dart';
import 'package:study_flutter/yzhg/project/shop/model/GoodsDetailBean.dart';
import 'package:study_flutter/yzhg/project/shop/provide/GoodsDetailProvide.dart';

import 'GoodsDetailWidget.dart';
import 'GoodsExplain.dart';

//  Provide.value<ChildCategory>(context).getChildCategory(childList);

class YGoodsDetailPages extends StatelessWidget {
  String goodsId;

  YGoodsDetailPages({String goodsId}) {
    this.goodsId = goodsId;
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
        future: _getGoodsDetailResult(context),
        builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
          print("==========================");
          print(snapshot);
          print("==========================");
          return GoodsDetailWidget();
        });
  }

  Future<String> _getGoodsDetailResult(BuildContext context) async {
    await getGoodsDetailData(goodsId).then((data) {
      print("====================_getGoodsDetailResult==================");
      var goodsDetail = json.decode(data.toString());
      GoodsDetailBean goodsDetailBean = GoodsDetailBean.fromJson(goodsDetail);
      GoodInfo goodInfo = goodsDetailBean.data.goodInfo;
      List<GoodComments> goodComments = goodsDetailBean.data.goodComments;
      Provide.value<GoodsDetailProvide>(context).getGoodInfo(goodInfo);
      Provide.value<GoodsDetailProvide>(context).getGoodComments(goodComments);
      print(data);
    });
    return "完成加载";
  }
}
